package com.touch.workshop.ui;
import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import com.touch.util.IntTools;
import com.touch.workshop.Database;
import com.touch.workshop.ui.expgrowth.CurveControls;
public class LevelLimits extends JInternalFrame implements InternalFrameListener, KeyListener
{
	private static final long serialVersionUID = -4913655263224719083L;
	
	protected JTextField minimum = new JTextField(8);
	protected JTextField maximum = new JTextField(8);
	
	public LevelLimits()
	{
		super("Level Limits", true, true, true, true);
		this.setSize(300, 60);
		this.setLayout(new FlowLayout());
		this.addInternalFrameListener(this);		
		
		this.add(new JLabel("Range :"));
		this.add(this.minimum);
		this.add(this.maximum);
		
		this.maximum.addKeyListener(this);
		this.minimum.addKeyListener(this);
		this.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
		this.update();
	}
	public void update()
	{
		this.minimum.setText(Integer.toString(Database.MINLEVEL));
		this.maximum.setText(Integer.toString(Database.MAXLEVEL));
	}
	public void setValues()
	{
		int oldMax = Database.MAXLEVEL;
		Database.MINLEVEL = (int)IntTools.getValue(this.minimum.getText());
		Database.MAXLEVEL = (int)IntTools.getValue(this.maximum.getText());	
		while(oldMax > Database.MAXLEVEL)
		{
			Database.EXPCHART.removeElementAt(Database.EXPCHART.lastElement());
			oldMax --;
		}
		while(oldMax < Database.MAXLEVEL)
		{
			Database.EXPCHART.add(new Integer(oldMax * 1500));
			oldMax ++;
		}
		CurveControls.update();
	}
	public void internalFrameActivated(InternalFrameEvent arg0)	{}
	public void internalFrameClosed(InternalFrameEvent arg0) 		{}
	public void internalFrameClosing(InternalFrameEvent arg0) 
	{	
		this.setValues();
	}
	public void internalFrameDeactivated(InternalFrameEvent arg0) {}
	public void internalFrameDeiconified(InternalFrameEvent arg0) {}
	public void internalFrameIconified(InternalFrameEvent arg0) 	{}
	public void internalFrameOpened(InternalFrameEvent arg0) 		{}
	public void keyPressed(KeyEvent e) 
	{
		if(e.getKeyCode() == KeyEvent.VK_ENTER)
		{
			this.setValues();
			this.setVisible(false);
		}		
	}
	public void keyReleased(KeyEvent arg0) 			{}
	public void keyTyped(KeyEvent arg0) 			{}	
}
